// by Xeno
#define THIS_FILE "fn_checkhelipilot.sqf"
#include "x_setup.sqf"
private ["_listin", "_no_lift", "_vehicle", "_position", "_enterer", "_exit_it", "_may_fly", "_type_enterer","_was_engineon"];

PARAMS_1(_listin);
_enterer = _listin select 2;
if (_enterer != player) exitWith {};

_no_lift = _this select 1;
_vehicle = _listin select 0;
_position = _listin select 1;

_was_engineon = isEngineOn _vehicle;

_exit_it = false;

#ifdef __TT__
_d_side = GV(_vehicle,GVAR(side));
if (!isNil "_d_side") then {
	if (GVAR(player_side) == blufor && {_d_side == opfor}) then {
		_exit_it = true;
		[(localize "STR_DOM_MISSIONSTRING_173"), "SIDE"] call FUNC(HintChatMsg);
	} else {
		if (GVAR(player_side) == opfor && {_d_side == blufor}) then {
			_exit_it = true;
			[(localize "STR_DOM_MISSIONSTRING_174"), "SIDE"] call FUNC(HintChatMsg);
		};
	};
};
#endif

if (!_exit_it && {_position == "driver"}) then {
	_may_fly = true;
	if (GVAR(pilots_only) == 0 && {!(call FUNC(isPilotCheck))}) then {
		_may_fly = false;
		//hintSilent (localize "STR_DOM_MISSIONSTRING_175");
		_exit_it = true;
	};
	if (_may_fly) then {
		if (_no_lift == 0) then {
			if (GVAR(chophud_on)) then {
				__pSetVar [QGVAR(hud_id), _vehicle addAction [(localize "STR_DOM_MISSIONSTRING_176") call FUNC(GreyText), {_this call FUNC(sethud)},0,-1,false]];
			} else {
				__pSetVar [QGVAR(hud_id), _vehicle addAction [(localize "STR_DOM_MISSIONSTRING_177") call FUNC(GreyText), {_this call FUNC(sethud)},1,-1,false]];
			};
			
			[_vehicle] spawn FUNC(helilift);
		};
	};
};

if (_exit_it) exitWith {
	if (!_was_engineon && {isEngineOn _vehicle}) then {
		_vehicle engineOn false;
		_enterer action ["engineOff", _vehicle];
	};
	_enterer action["Eject",_vehicle];
};